#include "Player.hpp"

#include "ImageManager.hpp"
#include "Missile.hpp"

Player::Player()
	: m_skin(SpriteManager::get()->sprite("data/player.png")),
	m_weapon(Missile(0,0,0,-350,true), 0.1),
	m_shoot(false)
{
	//m_skin.SetOrigin( m_skin.GetSize().x / 2, m_skin.GetSize().y / 2 );
}

Player::~Player()
{

}

void Player::event(const sf::Input& inpt)
{
    // on mouse move
	m_skin.SetX(inpt.GetMouseX() - m_skin.GetImage()->GetWidth()/2);
	m_skin.SetY(inpt.GetMouseY() - m_skin.GetImage()->GetHeight()/2);
	m_weapon.setPosition(inpt.GetMouseX(), inpt.GetMouseY());

	// on mouse left click
	m_shoot = inpt.IsMouseButtonDown(sf::Mouse::Left);
}

void Player::update(float dt)
{
	if (m_shoot)
	{
		shoot();
    }
}

void Player::show(sf::RenderTarget& wdw) const
{
	wdw.Draw(m_skin);
}

void Player::shoot()
{
	m_weapon.shoot();
}

